/**
 * Created by GadflyBSD on 16/3/12.
 */
angular.module('myApp.index', ['ngRoute'])
	.controller('indexCtrl', ['$scope', 'shopService', function($scope, shopService){

}]);

angular.module('myApp.shop', ['ngRoute', 'ui.bootstrap']).
controller('shopCtrl', ['$scope', '$uibModal', 'shopService', function($scope, $uibModal, shopService) {
	$scope.name = 'my Name';
	shopService.getShopList().success(function(resp){
		$scope.shopList = resp.data;
	});
	$scope.pageChanged = function() {
		shopService.getShopList($scope.currentPage).success(function(resp){
			$scope.shopList = resp.data;
		});
	};
}]);

angular.module('myApp.money', ['ngRoute', 'ui.bootstrap']).
controller('moneyCtrl', ['$scope', 'shopService', '$uibModal', 'dialogs', function($scope, shopService, $uibModal, dialogs){
	$scope.today = function(){ $scope.start = new Date(); };
	$scope.today();
	$scope.clear = function(){ $scope.start = null; };
	$scope.disabled = function(date, mode) {
		return mode === 'day' && date.getDay() === 0 ;
	};
	$scope.toggleMin = function(){ $scope.minDate = $scope.minDate ? null : new Date(); };
	$scope.toggleMin();
	$scope.maxDate = new Date(2020, 5, 22);
	$scope.calendar1 = function(){$scope.popup1.opened = true;};
	$scope.calendar2 = function(){$scope.popup2.opened = true;};
	$scope.setDate = function(year, month, day) { $scope.start = new Date(year, month, day); };
	$scope.dateOptions = {formatYear: 'yy', startingDay: 1};
	$scope.formats = ['yyyy年MM月dd日', 'yyyy/MM/dd', 'yyyy-MM-dd', 'shortDate'];
	$scope.format = $scope.formats[0];
	$scope.altInputFormats = ['yyyy年MM月dd日'];
	$scope.popup1 = {opened: false};
	$scope.popup2 = {opened: false};
	var tomorrow = new Date();
	tomorrow.setDate(tomorrow.getDate() + 1);
	var afterTomorrow = new Date();
	afterTomorrow.setDate(tomorrow.getDate() + 1);
	$scope.events =[
		{date: tomorrow, status: 'full'},
		{date: afterTomorrow, status: 'partially'}
	];
	$scope.getDayClass = function(date, mode) {
		if (mode === 'day') {
			var dayToCheck = new Date(date).setHours(0,0,0,0);
			for (var i = 0; i < $scope.events.length; i++) {
				var currentDay = new Date($scope.events[i].date).setHours(0,0,0,0);
				if (dayToCheck === currentDay) {
					return $scope.events[i].status;
				}
			}
		}
		return '';
	};
	function returnDay(param){
		if(param == 'today')
			var day = new Date();
		else
			var day = new Date(param);
		return day.getFullYear()+'-'+(day.getMonth()+1)+'-'+day.getDate();
	}
	shopService.getSettleList(returnDay('today'), returnDay('today')).success(function(resp){
		$scope.settleList = resp.data;
	});
	$scope.searchs = function(){
		var start = returnDay($scope.searchs.start);
		var end = returnDay($scope.searchs.end);
		shopService.getSettleList(start, end).success(function(resp){
			$scope.settleList = resp.data;
		});
	}
	$scope.checkWithdraw = function(){

	}
	$scope.checkWithdrawAll = function(){

	}
	$scope.chk = function(x, y){
		console.log($scope, x, y);
	}
}]);

angular.module('myApp.person', ['ngRoute', 'ui.bootstrap']).
controller('personCtrl', ['$scope', 'shopService', 'dialogs', function($scope, shopService, dialogs){
	shopService.getSurveyList().success(function(resp){
		$scope.surveyList = resp.data;
		$scope.removeSurveyBind = function(bid){
			shopService.removeSurveyBind(bid).success(function(){
				dialogs.error(resp.title, resp.content).result.then(function(){
					location.reload(true);
				});
			});
		}
	});
}]);
angular.module('myApp.recharge', ['ngRoute']).controller('rechargeCtrl', ['$scope', 'shopService', function($scope, shopService) {
	$scope.sendSms = function(){
		shopService.sendSms(attrs.mobile, attrs.ac).success(function(resp){
			scope.forms.sms_order_id = resp.data.order_id;
			scope.forms.sms_order_date = resp.data.order_date;
			alert(resp);
		});
	}
}]);
angular.module('myApp.user', ['ngRoute']).controller('userCtrl', [function() {

}]);

angular.module('myApp.setting', ['ngRoute']).
controller('settingCtrl', ['$scope', function($scope) {}]);